﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Admin.Master" AutoEventWireup="true" CodeBehind="frm_Usuario.aspx.cs" Inherits="ED_Nivelacion.PresentacionWeb.Usuario" %>

<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="ajaxToolkit" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
    <style type="text/css">
        .auto-style1
        {
            width: 358px;
        }
        .auto-style4 {
            width: 126px;
        }
        .auto-style5 {
            width: 168px;
        }
        .auto-style6 {
            width: 191px;
        }
    </style>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
 

    <form id="Form1" runat="server">

        <script>
            function show() {
                document.write("<head id='head2' runat='server'></head>");
            }
</script>
        <script>

            var p = "";


           // $(document).ready(function () {
               


                $("#ContentPlaceHolder1_cbm_TipoU").on("change", function () {
                    var valor = $("#ContentPlaceHolder1_cbm_TipoU").val();
                    if (valor === "5"  ||  valor === true) {
                        $("#ContentPlaceHolder1_Cbm_Periodo").attr('disabled', false);
                        //$("#ContentPlaceHolder1_Cbm_Periodo").show();
                    } else if (valor === "1" || valor === "0" || valor === false) {

                        // deshabilitamos
                       // $("#ContentPlaceHolder1_Cbm_Periodo").hide();
                        $("#ContentPlaceHolder1_Cbm_Periodo").val(0);
                        $("#ContentPlaceHolder1_Cbm_Periodo").attr('disabled', true);
                        //$("#ContentPlaceHolder1_Cbm_Periodo").attr('hide', true);
                    }

                   
                });




                $(document).on("click", ".editar", function () {

                    var nombre = $(this).data("nombre");
                    var apellido = $(this).data("apellido");
                    var cedula = $(this).data("cedula");
                    var persona = $(this).data("persona");


                    $('#ContentPlaceHolder1_txt_CCUsuario').val(cedula);
                    $('#ContentPlaceHolder1_txt_ApellidosU').val(apellido);
                    $('#ContentPlaceHolder1_txt_NombresU').val(nombre);
                    $('#ContentPlaceHolder1_txtIdPersona').val(persona);


                    $('#ContentPlaceHolder1_btn_Editar').show();
                    $('#ContentPlaceHolder1_Btn_Guardar_Usuario').hide();
                });

                $(document).on("click", ".guardar", function () {
                    $('#ContentPlaceHolder1_btn_Editar').hide();
                    $('#ContentPlaceHolder1_Btn_Guardar_Usuario').show();
                });
          


            function limpiar() {
                $('#ContentPlaceHolder1_txt_CCUsuario').val("");
                $('#ContentPlaceHolder1_txt_ApellidosU').val("");
                $('#ContentPlaceHolder1_txt_NombresU').val("");
            }

           function Desvincular(Persona) {
               ED_Nivelacion.PresentacionWeb.ServiciosLocales.CuestionarioService.EliminarAdministrador(Persona, sucessD, errorD);


                p = Persona;
            }

            function sucessD()
            {
                errorMessage("Desvinculado");
                //alert(p);
                $('#v'+p).removeClass("hide");
                $('#v'+p).show;
                $('#d'+p).addClass("hide");
            }

            function errorD()
            {
                alert("Error");
            }

            function Vincular(Persona)
            {
               //alert(Persona);
                var data = {idPersona: Persona};
                ED_Nivelacion.PresentacionWeb.ServiciosLocales.CuestionarioService.AgregarAdministrador(data, sucess, error);
                p = Persona;
            }

            function sucess() {
                sucessMessage("Vinculado");
                $('#d'+p).removeClass("hide");
                $('#d'+p).show;
                $('#v'+p).addClass("hide");
            }

            function error() {
                errorMessage("Error");
            }



        </script>

        <% ED_Nivelacion.Negocios.Persona_C _objPersona_C = new ED_Nivelacion.Negocios.Persona_C();
           ED_Nivelacion.Negocios.TipoUsuario_C _objUsuario_C = new ED_Nivelacion.Negocios.TipoUsuario_C(); 
           ED_Nivelacion.Negocios.Administrador_C _objAdmin_C = new ED_Nivelacion.Negocios.Administrador_C();
           %>
                

                

        <div class="col-lg-22">
        <asp:ScriptManager ID="ScriptManager1" runat="server">
            <Services>
                <asp:ServiceReference Path="~/ServiciosLocales/CuestionarioService.asmx" />
            </Services>
        </asp:ScriptManager>
        <asp:Timer ID="Timer1" runat="server">
                                </asp:Timer>
                        <div class="portlet portlet-default">
                            <div class="portlet-heading">
                                <div class="portlet-title">
                                    <h4>TABLA DE USUARIOS</h4>

                                </div>
                                <div class="clearfix">
                                    <div class ="portlet-widgets"> 
                                        <a class ="btn btn-success btn-xs guardar" data-toggle ="modal" data-target ="#aa" onclick="limpiar()"> <i class ="fa fa-plus"> Agregar </i> </a>   
                                    </div>
                                </div>
                            </div>
                            <div class="portlet-body">
                                <div class="table-responsive"> 
                                    
                                    <table id="example-table" class="table table-striped table-bordered table-hover table-green">
                                        <thead>
                                            <tr>
                                                <th>#</th>
                                                <th class="auto-style5">NOMBRE</th>
                                                <th class="auto-style6">APELLIDO</th>
                                                <th>CEDULA O PASAPORTE</th>
                                                <th class="auto-style4">CLAVE</th>
                                                <th>PERMISOS</th>
                                                <th>ACCIÓN</th>
                                            </tr>
                                        </thead>

                                        <tbody>
                                                                                    <% foreach (var item in _objPersona_C.ObtenerPersonaAdmin())
                                       {
                                                                                    
                                           var n = _objAdmin_C.ObtenerAdministrador().Where(c => c.idPersona == item.idPersona).Count();
                                        %>
                                            <tr class="odd gradeX">
                                                <td><% = item.idPersona %></td>
                                                <td class="auto-style5"><% = item.Nombre %></td>
                                                <td class="auto-style6"><% = item.Apellido %></td>
                                                <td class="center"><% = item.Cedula %></td>
                                                <td class="auto-style4"><% = item.Clave %></td>
                                                <td><%if(n == 0){ %><a id="v<%=item.idPersona %>" class ="btn btn-green btn-sm" data-per="<%=item.idPersona %>" onclick="Vincular(<%=item.idPersona %>)"><i class ="fa fa-sign-in"></i> VINCULAR </a>
                                                <a class ="btn btn-red btn-sm desvincular hide" id="d<%=item.idPersona %>" data-per="<%=item.idPersona %>" onclick="Desvincular(<%=item.idPersona %>)"><i class ="fa fa-sign-out"></i> DESVINCULAR </a>
                                                    <%}else{ %><a class ="btn btn-red btn-sm" id="d<%=item.idPersona %>" data-per="<%=item.idPersona %>" onclick="Desvincular(<%=item.idPersona %>)"><i class ="fa fa-sign-out"></i> DESVINCULAR </a>
                                                    <a class ="btn btn-green btn-sm hide" id="v<%=item.idPersona %>" data-per="<%=item.idPersona %>" onclick="Vincular(<%=item.idPersona %>)"><i class ="fa fa-sign-in"></i> VINCULAR </a>
                                                <%} %>
                                                </td>
                                               <td class="center"> <a class ="btn btn-orange btn-sm editar" data-toggle="modal" data-target="#aa" data-nombre="<%=item.Nombre%>" data-apellido="<%=item.Apellido%>" data-cedula="<%=item.Cedula%>" data-persona="<%=item.idPersona %>"><i class ="fa fa-pencil"></i> MODIFICAR </a>
                                               </td>
                                            </tr>
                                                                                    <%   
                                 } %>
                                        </tbody>

                                        <asp:TextBox ID="idEliminar" runat="server" CssClass="hidden"></asp:TextBox>

                                    </table>
                                     
                                </div>
                                <!-- /.table-responsive -->
                            </div>
                            <!-- /.portlet-body -->
                        </div>
                        <!-- /.portlet -->

                    </div>

        <div class="col-lg-12">
    <div class="modal modal-flex fade" id="aa" tabindex="-1" role="dialog" aria-labelledby="flexModalLabel" aria-hidden="true">
                                    <div class="modal-dialog">
                                        <div class="modal-content">
                                            <div class="modal-header">
                                                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                                                <h4 class="modal-title" id="flexModalLabel">Ingreso de Nuevo Usuario</h4>
                                            </div>
                                            <div id="Div1" class="modal-body" runat="server">
                                                <div class="panel panel-default">
 
                            <div class="panel-body">
                                <div class="table-responsive">
                                    <asp:TextBox ID="txtIdPersona" runat="server" CssClass="hidden"></asp:TextBox>
                                    <table class="table table-striped table-bordered table-hover">
                                        <thead>
                                            <tr>
                                                <th class="auto-style1">Datos</th>
                                                <th>Docente</th>
                                            </tr>
                                        </thead>
                                        <tbody>
                                            <tr>
                                                <td class="auto-style1">C.C. o Pasaporte:</td>
                                                <td>
                                                    <asp:TextBox ID="txt_CCUsuario" required runat="server"></asp:TextBox>
                                                </td>
                                            </tr>
                                            <tr>
                                                <td class="auto-style1">Apellidos:</td>
                                                <td>
                                                    <asp:TextBox ID="txt_ApellidosU" required runat="server"></asp:TextBox>
                                                    <ajaxToolkit:FilteredTextBoxExtender ID="FilteredTextBoxExtender1" runat="server" TargetControlID="txt_ApellidosU" FilterType="LowercaseLetters,UppercaseLetters,Custom" ValidChars="ñÑáéíóúÁÉÍÓÚ " />
                                                </td>
                                            </tr>
                                            <tr>
                                                <td class="auto-style1">Nombres:</td>
                                                <td>
                                                    <asp:TextBox ID="txt_NombresU" required runat="server"></asp:TextBox>
                                                    <ajaxToolkit:FilteredTextBoxExtender ID="FilteredTextBoxExtender2" runat="server" TargetControlID="txt_NombresU" FilterType="LowercaseLetters,UppercaseLetters,Custom" ValidChars="ñÑáéíóúÁÉÍÓÚ " />
                                                </td>
                                            </tr>

                                        </tbody>
                                    </table>
                                </div>
                            </div>
                        </div>
                                            </div>
                                            <div class="modal-footer">
                                              <asp:Button ID="Btn_Guardar_Usuario" runat="server" cssClass="btn btn-primary btn-sm" Text="GUARDAR" OnClick="Btn_Guardar_Usuario_Click" />
                                              <asp:Button ID="btn_Editar" runat="server" CssClass=" btn btn-primary btn-sm" Text="EDITAR" OnClick="btn_Editar_Click" />

                                            </div>
                                        </div>
                                        <!-- /.modal-content -->
                                    </div>
                                    <!-- /.modal-dialog -->
                                </div>
                                <!-- /.modal --> 
               </div>

        <script>
            $('[data-per]').click(function () {
                var Id = $(this).data('per');
                $("#ContentPlaceHolder1_idEliminar").val(Id);
                //alert(Id);
            });

            $('[data-toggle="confirmation"]').confirmation({
                placement: 'top', // How to position the confirmation - top | bottom | left | right
                trigger: 'click', // How confirmation is triggered - click | hover | focus | manual
                title: 'Esta seguro?', // Default title value if `data-title` attribute isn't present  
                template: '<div class="popover" >' +
                    '<div class="arrow"></div>' +
                    '<h3 class="popover-title"></h3>' +
                    '<div class="popover-content text-center">' +
                    '<div id="botones" class="btn-group">' +
                    '<asp:LinkButton ID="BtnEliminar" runat="server" CssClass="btn btn-success btn-xs" OnClick="Delete_Click"><i class="fa fa-check-circle icon-white"></i> Si</asp:LinkButton>' +
                    '<a class="btn btn-xs" data-dismiss="confirmation"></a>' +
                    '</div>' +
                    '</div>'
                , btnOkClass: 'btn-primary'
                , btnOkIcon: 'fa fa-check-circle'
                , btnCancelClass: 'btn-danger'
                , btnOkLabel: 'Si'
                , btnCancelIcon: 'fa fa-times-circle'
                , btnCancelLabel: 'No',
                singleton: true, // Set true to allow only one confirmation to show at a time.
                popout: false, // Set true to hide the confirmation when user clicks outside of it.
                onConfirm: function () {

                }, // Set event when click at confirm button
                onCancel: function () { }
            }); // Set event when click at cancel button
    </script>
        </form>
</asp:Content>
